<template>
  <div class="home-container">
    <header class="header">
      <div class="logo-title">
        <img src="@/assets/lawyerlogo.png" alt="山西东奥律师事务所" class="logo">
        <h1 class="law-firm-name">{{ lawFirmName }}</h1>
      </div>
    </header>

    <main class="main-content">
      <div class="intro-section">
        <div class="intro-text">
          <h2>专业 · 诚信 · 卓越</h2>
          <p>山西东奥律师事务所成立于2004年，是经山西省司法厅批准设立的综合性律师事务所，位于太原市万柏林区迎泽西大街。</p>
          <p>我们拥有47名执业律师和14名助理团队，在民商事诉讼、刑事诉讼、法律顾问等传统业务基础上，发展了金融、证券、房地产、知识产权等专业领域服务。</p>
          <div class="highlights">
            <div class="highlight-item">
              <span class="highlight-icon">🏛️</span>
              <h3>综合性业务</h3>
              <p>业务范围全面，团队合作精神强</p>
            </div>
            <div class="highlight-item">
              <span class="highlight-icon">📚</span>
              <h3>丰富经验</h3>
              <p>定期法律培训，理论实践结合</p>
            </div>
            <div class="highlight-item">
              <span class="highlight-icon">🤝</span>
              <h3>公共关系</h3>
              <p>良好沟通协调能力，广泛社会资源</p>
            </div>
          </div>
        </div>
        <div class="auth-box">
          <div v-if="!showLoginForm" class="auth-options">
            <h3 class="auth-title">东奥律师事务所</h3>
            <button @click="showLoginForm = true" class="auth-option login-option">
              <span class="auth-icon">🔑</span>
              <span>会员登录</span>
            </button>
            <button @click="goToMembership" class="auth-option join-option">
              <span class="auth-icon">📝</span>
              <span>入会申请</span>
            </button>
          </div>

          <div v-else class="login-form">
            <h3 class="login-title">会员登录</h3>
            <el-form
              ref="loginFormRef"
              :model="loginForm"
              :rules="loginRules"
              label-width="80px"
              :hide-required-asterisk="true"
            >
              <el-form-item label="用户名" prop="username">
                <el-input v-model="loginForm.username" />
              </el-form-item>
              <el-form-item label="密码" prop="password">
                <el-input v-model="loginForm.password" type="password" show-password />
              </el-form-item>
              <el-form-item>
                <el-button type="primary" @click="submitForm(loginFormRef)">
                  登录
                </el-button>
                <el-button @click="resetForm(loginFormRef)">取消</el-button>
              </el-form-item>
            </el-form>
            <div class="back-option" @click="showLoginForm = false">
              &lt; 返回
            </div>
          </div>
        </div>
      </div>
    </main>
  </div>
</template>

<script setup>
import { ref, reactive } from 'vue'
import { useRouter } from 'vue-router'
import { ElMessage } from 'element-plus'

const router = useRouter()
const lawFirmName = ref('山西东奥律师事务所')
const showLoginForm = ref(false)
const loginFormRef = ref()

const loginForm = reactive({
  username: '',
  password: ''
})

const validatePassword = (rule, value, callback) => {
  if (value === '') {
    callback(new Error('密码不能为空'))
  } else {
    // 正则表达式
    let reg = /^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{8,15}$/
    if (!reg.test(value)) {
      callback(new Error('密码由字母数字组成的8-15位'))
    } else {
      callback()
    }
  }
}

const loginRules = reactive({
  username: [
    { required: true, message: '用户名不能为空', trigger: 'blur' },
    { min: 5, max: 10, message: '用户名的长度是5-10', trigger: 'blur' },
  ],
  password: [
    { validator: validatePassword, trigger: 'blur' }
  ]
})

const submitForm = (formEl) => {
  if (!formEl) return

  formEl.validate((valid) => {
    if (valid) {
      // 模拟登录成功
      ElMessage.success('登录成功！')
      // 在实际应用中，这里会调用API并跳转
      setTimeout(() => {
        router.push("/dashboard")
      }, 1000)
    } else {
      ElMessage.error('请正确填写表单')
      return false
    }
  })
}

const resetForm = (formEl) => {
  if (!formEl) return
  formEl.resetFields()
  showLoginForm.value = false
}

const goToMembership = () => {
  router.push("/seeker")
}
</script>

<style scoped>
.home-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
  font-family: 'Microsoft YaHei', 'PingFang SC', sans-serif;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 40px;
  padding: 20px 0;
  border-bottom: 1px solid #eee;
}

.logo-title {
  display: flex;
  align-items: center;
  gap: 20px;
}

.logo {
  height: 60px;
  width: auto;
}

.law-firm-name {
  font-size: 1.8rem;
  color: #1a3e72;
  font-weight: bold;
  margin: 0;
}

.main-content {
  line-height: 1.8;
  color: #444;
}

.intro-section {
  display: flex;
  gap: 40px;
  margin-top: 30px;
}

.intro-text {
  flex: 1;
}

.intro-text h2 {
  color: #1a3e72;
  font-size: 2rem;
  margin-bottom: 20px;
}

.intro-text p {
  margin-bottom: 15px;
  font-size: 1.1rem;
}

/* 右侧认证框样式 */
.auth-box {
  flex: 0 0 320px;
  align-self: flex-start;
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 5px 15px rgba(0,0,0,0.08);
  padding: 25px;
  position: sticky;
  top: 20px;
  transition: all 0.3s ease;
}

.auth-options {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.auth-title {
  color: #1a3e72;
  font-size: 1.2rem;
  text-align: center;
  margin-bottom: 20px;
  padding-bottom: 10px;
  border-bottom: 1px solid #eee;
}

.auth-option {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 12px 15px;
  border: none;
  border-radius: 8px;
  font-size: 0.95rem;
  cursor: pointer;
  transition: all 0.3s ease;
  background: #f8f9fa;
  color: #333;
  width: 100%;
}

.auth-option:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}

.login-option:hover {
  background: #e6f0ff;
  color: #1a3e72;
}

.join-option:hover {
  background: #f0f7ff;
  color: #1a3e72;
}

.auth-icon {
  font-size: 1.2rem;
}

.highlights {
  display: flex;
  justify-content: space-between;
  margin-top: 30px;
  gap: 20px;
}

.highlight-item {
  flex: 1;
  padding: 20px;
  background: #f8f9fa;
  border-radius: 8px;
  text-align: center;
  transition: transform 0.3s ease;
}

.highlight-item:hover {
  transform: translateY(-5px);
  box-shadow: 0 5px 15px rgba(0,0,0,0.1);
}

.highlight-icon {
  font-size: 2rem;
  display: block;
  margin-bottom: 10px;
}

.highlight-item h3 {
  color: #1a3e72;
  margin: 10px 0;
}

.highlight-item p {
  font-size: 0.9rem;
  color: #666;
}

/* 登录表单样式 */
.login-form {
  padding: 10px 0;
}

.login-title {
  color: #1a3e72;
  text-align: center;
  margin-bottom: 20px;
  font-size: 1.4rem;
}

.back-option {
  text-align: center;
  margin-top: 15px;
  color: #1a3e72;
  cursor: pointer;
  font-size: 0.9rem;
}

.back-option:hover {
  text-decoration: underline;
}

@media (max-width: 768px) {
  .intro-section {
    flex-direction: column;
  }

  .auth-box {
    width: 100%;
    flex: none;
  }

  .highlights {
    flex-direction: column;
  }
}
</style>
